package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-05-28
 * Time: 10:40
 */
public class DelOperation implements IOPeration {
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除图书名:");
        String name = scanner.nextLine();
        int cur = bookList.getUserSize();
        for (int i = 0; i < bookList.getUserSize(); i++) {
            if (name.equals(bookList.getBooks(i).getName())) {
                //删除
                for (int j = i; j < cur-1; j++) {
                    Book book = bookList.getBooks(j+1);
                    bookList.setBooks(j,book);
                }
                bookList.setBooks(cur-1,null);
                System.out.println("删除成功!");
                bookList.setUserSize(cur-1);
                return;
            }
        }
        System.out.println("没有这本书!");
    }
}
